
/*
===============================================================================
                    EntitySpaces Studio by EntitySpaces, LLC
             Persistence Layer and Business Objects for Microsoft .NET
             EntitySpaces(TM) is a legal trademark of EntitySpaces, LLC
                          http://www.entityspaces.net
===============================================================================
EntitySpaces Version : 2012.1.0930.0
EntitySpaces Driver  : SQL
Date Generated       : 3/29/2013 2:25:55 PM
===============================================================================
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Linq;
using System.Data;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Runtime.Serialization;

using EntitySpaces.Core;
using EntitySpaces.Interfaces;
using EntitySpaces.DynamicQuery;



namespace DNNspot.LiveChat.DataModel
{
	/// <summary>
	/// Encapsulates the 'Users' table
	/// </summary>

    [DebuggerDisplay("Data = {Debug}")]
	[Serializable]
	[DataContract]
	[KnownType(typeof(User))]	
	[XmlType("User")]
	public partial class User : esUser
	{	
		[DebuggerBrowsable(DebuggerBrowsableState.RootHidden | DebuggerBrowsableState.Never)]
		protected override esEntityDebuggerView[] Debug
		{
			get { return base.Debug; }
		}

		override public esEntity CreateInstance()
		{
			return new User();
		}
		
		#region Static Quick Access Methods
		static public void Delete(System.Int32 userID)
		{
			var obj = new User();
			obj.UserID = userID;
			obj.AcceptChanges();
			obj.MarkAsDeleted();
			obj.Save();
		}

	    static public void Delete(System.Int32 userID, esSqlAccessType sqlAccessType)
		{
			var obj = new User();
			obj.UserID = userID;
			obj.AcceptChanges();
			obj.MarkAsDeleted();
			obj.Save(sqlAccessType);
		}
		#endregion

		
					
		
	
	}



    [DebuggerDisplay("Count = {Count}")]
	[Serializable]
	[CollectionDataContract]
	[XmlType("UserCollection")]
	public partial class UserCollection : esUserCollection, IEnumerable<User>
	{
		public User FindByPrimaryKey(System.Int32 userID)
		{
			return this.SingleOrDefault(e => e.UserID == userID);
		}

		
		
		#region WCF Service Class
		
		[DataContract]
		[KnownType(typeof(User))]
		public class UserCollectionWCFPacket : esCollectionWCFPacket<UserCollection>
		{
			public static implicit operator UserCollection(UserCollectionWCFPacket packet)
			{
				return packet.Collection;
			}

			public static implicit operator UserCollectionWCFPacket(UserCollection collection)
			{
				return new UserCollectionWCFPacket() { Collection = collection };
			}
		}
		
		#endregion
		
				
	}



    [DebuggerDisplay("Query = {Parse()}")]
	[Serializable]	
	public partial class UserQuery : esUserQuery
	{
		public UserQuery(string joinAlias)
		{
			this.es.JoinAlias = joinAlias;
		}	

		override protected string GetQueryName()
		{
			return "UserQuery";
		}
		
					
	
		#region Explicit Casts
		
		public static explicit operator string(UserQuery query)
		{
			return UserQuery.SerializeHelper.ToXml(query);
		}

		public static explicit operator UserQuery(string query)
		{
			return (UserQuery)UserQuery.SerializeHelper.FromXml(query, typeof(UserQuery));
		}
		
		#endregion		
	}

	[DataContract]
	[Serializable]
	abstract public partial class esUser : esEntity
	{
		public esUser()
		{

		}
		
		#region LoadByPrimaryKey
		public virtual bool LoadByPrimaryKey(System.Int32 userID)
		{
			if(this.es.Connection.SqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(userID);
			else
				return LoadByPrimaryKeyStoredProcedure(userID);
		}

		public virtual bool LoadByPrimaryKey(esSqlAccessType sqlAccessType, System.Int32 userID)
		{
			if (sqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(userID);
			else
				return LoadByPrimaryKeyStoredProcedure(userID);
		}

		private bool LoadByPrimaryKeyDynamic(System.Int32 userID)
		{
			UserQuery query = new UserQuery();
			query.Where(query.UserID == userID);
			return this.Load(query);
		}

		private bool LoadByPrimaryKeyStoredProcedure(System.Int32 userID)
		{
			esParameters parms = new esParameters();
			parms.Add("UserID", userID);
			return this.Load(esQueryType.StoredProcedure, this.es.spLoadByPrimaryKey, parms);
		}
		#endregion
		
		#region Properties
		
		
		
		/// <summary>
		/// Maps to Users.UserID
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Int32? UserID
		{
			get
			{
				return base.GetSystemInt32(UserMetadata.ColumnNames.UserID);
			}
			
			set
			{
				if(base.SetSystemInt32(UserMetadata.ColumnNames.UserID, value))
				{
					OnPropertyChanged(UserMetadata.PropertyNames.UserID);
				}
			}
		}		
		
		/// <summary>
		/// Maps to Users.Username
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String Username
		{
			get
			{
				return base.GetSystemString(UserMetadata.ColumnNames.Username);
			}
			
			set
			{
				if(base.SetSystemString(UserMetadata.ColumnNames.Username, value))
				{
					OnPropertyChanged(UserMetadata.PropertyNames.Username);
				}
			}
		}		
		
		/// <summary>
		/// Maps to Users.FirstName
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String FirstName
		{
			get
			{
				return base.GetSystemString(UserMetadata.ColumnNames.FirstName);
			}
			
			set
			{
				if(base.SetSystemString(UserMetadata.ColumnNames.FirstName, value))
				{
					OnPropertyChanged(UserMetadata.PropertyNames.FirstName);
				}
			}
		}		
		
		/// <summary>
		/// Maps to Users.LastName
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String LastName
		{
			get
			{
				return base.GetSystemString(UserMetadata.ColumnNames.LastName);
			}
			
			set
			{
				if(base.SetSystemString(UserMetadata.ColumnNames.LastName, value))
				{
					OnPropertyChanged(UserMetadata.PropertyNames.LastName);
				}
			}
		}		
		
		/// <summary>
		/// Maps to Users.IsSuperUser
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Boolean? IsSuperUser
		{
			get
			{
				return base.GetSystemBoolean(UserMetadata.ColumnNames.IsSuperUser);
			}
			
			set
			{
				if(base.SetSystemBoolean(UserMetadata.ColumnNames.IsSuperUser, value))
				{
					OnPropertyChanged(UserMetadata.PropertyNames.IsSuperUser);
				}
			}
		}		
		
		/// <summary>
		/// Maps to Users.AffiliateId
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Int32? AffiliateId
		{
			get
			{
				return base.GetSystemInt32(UserMetadata.ColumnNames.AffiliateId);
			}
			
			set
			{
				if(base.SetSystemInt32(UserMetadata.ColumnNames.AffiliateId, value))
				{
					OnPropertyChanged(UserMetadata.PropertyNames.AffiliateId);
				}
			}
		}		
		
		/// <summary>
		/// Maps to Users.Email
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String Email
		{
			get
			{
				return base.GetSystemString(UserMetadata.ColumnNames.Email);
			}
			
			set
			{
				if(base.SetSystemString(UserMetadata.ColumnNames.Email, value))
				{
					OnPropertyChanged(UserMetadata.PropertyNames.Email);
				}
			}
		}		
		
		/// <summary>
		/// Maps to Users.DisplayName
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String DisplayName
		{
			get
			{
				return base.GetSystemString(UserMetadata.ColumnNames.DisplayName);
			}
			
			set
			{
				if(base.SetSystemString(UserMetadata.ColumnNames.DisplayName, value))
				{
					OnPropertyChanged(UserMetadata.PropertyNames.DisplayName);
				}
			}
		}		
		
		/// <summary>
		/// Maps to Users.UpdatePassword
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Boolean? UpdatePassword
		{
			get
			{
				return base.GetSystemBoolean(UserMetadata.ColumnNames.UpdatePassword);
			}
			
			set
			{
				if(base.SetSystemBoolean(UserMetadata.ColumnNames.UpdatePassword, value))
				{
					OnPropertyChanged(UserMetadata.PropertyNames.UpdatePassword);
				}
			}
		}		
		
		/// <summary>
		/// Maps to Users.LastIPAddress
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String LastIPAddress
		{
			get
			{
				return base.GetSystemString(UserMetadata.ColumnNames.LastIPAddress);
			}
			
			set
			{
				if(base.SetSystemString(UserMetadata.ColumnNames.LastIPAddress, value))
				{
					OnPropertyChanged(UserMetadata.PropertyNames.LastIPAddress);
				}
			}
		}		
		
		/// <summary>
		/// Maps to Users.IsDeleted
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Boolean? IsDeleted
		{
			get
			{
				return base.GetSystemBoolean(UserMetadata.ColumnNames.IsDeleted);
			}
			
			set
			{
				if(base.SetSystemBoolean(UserMetadata.ColumnNames.IsDeleted, value))
				{
					OnPropertyChanged(UserMetadata.PropertyNames.IsDeleted);
				}
			}
		}		
		
		/// <summary>
		/// Maps to Users.CreatedByUserID
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Int32? CreatedByUserID
		{
			get
			{
				return base.GetSystemInt32(UserMetadata.ColumnNames.CreatedByUserID);
			}
			
			set
			{
				if(base.SetSystemInt32(UserMetadata.ColumnNames.CreatedByUserID, value))
				{
					OnPropertyChanged(UserMetadata.PropertyNames.CreatedByUserID);
				}
			}
		}		
		
		/// <summary>
		/// Maps to Users.CreatedOnDate
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.DateTime? CreatedOnDate
		{
			get
			{
				return base.GetSystemDateTime(UserMetadata.ColumnNames.CreatedOnDate);
			}
			
			set
			{
				if(base.SetSystemDateTime(UserMetadata.ColumnNames.CreatedOnDate, value))
				{
					OnPropertyChanged(UserMetadata.PropertyNames.CreatedOnDate);
				}
			}
		}		
		
		/// <summary>
		/// Maps to Users.LastModifiedByUserID
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Int32? LastModifiedByUserID
		{
			get
			{
				return base.GetSystemInt32(UserMetadata.ColumnNames.LastModifiedByUserID);
			}
			
			set
			{
				if(base.SetSystemInt32(UserMetadata.ColumnNames.LastModifiedByUserID, value))
				{
					OnPropertyChanged(UserMetadata.PropertyNames.LastModifiedByUserID);
				}
			}
		}		
		
		/// <summary>
		/// Maps to Users.LastModifiedOnDate
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.DateTime? LastModifiedOnDate
		{
			get
			{
				return base.GetSystemDateTime(UserMetadata.ColumnNames.LastModifiedOnDate);
			}
			
			set
			{
				if(base.SetSystemDateTime(UserMetadata.ColumnNames.LastModifiedOnDate, value))
				{
					OnPropertyChanged(UserMetadata.PropertyNames.LastModifiedOnDate);
				}
			}
		}		
		
		#endregion	

		#region .str() Properties
		
		public override void SetProperties(IDictionary values)
		{
			foreach (string propertyName in values.Keys)
			{
				this.SetProperty(propertyName, values[propertyName]);
			}
		}
		
		public override void SetProperty(string name, object value)
		{
			esColumnMetadata col = this.Meta.Columns.FindByPropertyName(name);
			if (col != null)
			{
				if(value == null || value is System.String)
				{				
					// Use the strongly typed property
					switch (name)
					{							
						case "UserID": this.str().UserID = (string)value; break;							
						case "Username": this.str().Username = (string)value; break;							
						case "FirstName": this.str().FirstName = (string)value; break;							
						case "LastName": this.str().LastName = (string)value; break;							
						case "IsSuperUser": this.str().IsSuperUser = (string)value; break;							
						case "AffiliateId": this.str().AffiliateId = (string)value; break;							
						case "Email": this.str().Email = (string)value; break;							
						case "DisplayName": this.str().DisplayName = (string)value; break;							
						case "UpdatePassword": this.str().UpdatePassword = (string)value; break;							
						case "LastIPAddress": this.str().LastIPAddress = (string)value; break;							
						case "IsDeleted": this.str().IsDeleted = (string)value; break;							
						case "CreatedByUserID": this.str().CreatedByUserID = (string)value; break;							
						case "CreatedOnDate": this.str().CreatedOnDate = (string)value; break;							
						case "LastModifiedByUserID": this.str().LastModifiedByUserID = (string)value; break;							
						case "LastModifiedOnDate": this.str().LastModifiedOnDate = (string)value; break;
					}
				}
				else
				{
					switch (name)
					{	
						case "UserID":
						
							if (value == null || value is System.Int32)
								this.UserID = (System.Int32?)value;
								OnPropertyChanged(UserMetadata.PropertyNames.UserID);
							break;
						
						case "IsSuperUser":
						
							if (value == null || value is System.Boolean)
								this.IsSuperUser = (System.Boolean?)value;
								OnPropertyChanged(UserMetadata.PropertyNames.IsSuperUser);
							break;
						
						case "AffiliateId":
						
							if (value == null || value is System.Int32)
								this.AffiliateId = (System.Int32?)value;
								OnPropertyChanged(UserMetadata.PropertyNames.AffiliateId);
							break;
						
						case "UpdatePassword":
						
							if (value == null || value is System.Boolean)
								this.UpdatePassword = (System.Boolean?)value;
								OnPropertyChanged(UserMetadata.PropertyNames.UpdatePassword);
							break;
						
						case "IsDeleted":
						
							if (value == null || value is System.Boolean)
								this.IsDeleted = (System.Boolean?)value;
								OnPropertyChanged(UserMetadata.PropertyNames.IsDeleted);
							break;
						
						case "CreatedByUserID":
						
							if (value == null || value is System.Int32)
								this.CreatedByUserID = (System.Int32?)value;
								OnPropertyChanged(UserMetadata.PropertyNames.CreatedByUserID);
							break;
						
						case "CreatedOnDate":
						
							if (value == null || value is System.DateTime)
								this.CreatedOnDate = (System.DateTime?)value;
								OnPropertyChanged(UserMetadata.PropertyNames.CreatedOnDate);
							break;
						
						case "LastModifiedByUserID":
						
							if (value == null || value is System.Int32)
								this.LastModifiedByUserID = (System.Int32?)value;
								OnPropertyChanged(UserMetadata.PropertyNames.LastModifiedByUserID);
							break;
						
						case "LastModifiedOnDate":
						
							if (value == null || value is System.DateTime)
								this.LastModifiedOnDate = (System.DateTime?)value;
								OnPropertyChanged(UserMetadata.PropertyNames.LastModifiedOnDate);
							break;
					

						default:
							break;
					}
				}
			}
            else if (this.ContainsColumn(name))
            {
                this.SetColumn(name, value);
            }
			else
			{
				throw new Exception("SetProperty Error: '" + name + "' not found");
			}
		}		

		public esStrings str()
		{
			if (esstrings == null)
			{
				esstrings = new esStrings(this);
			}
			return esstrings;
		}

		sealed public class esStrings
		{
			public esStrings(esUser entity)
			{
				this.entity = entity;
			}
			
	
			public System.String UserID
			{
				get
				{
					System.Int32? data = entity.UserID;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.UserID = null;
					else entity.UserID = Convert.ToInt32(value);
				}
			}
				
			public System.String Username
			{
				get
				{
					System.String data = entity.Username;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.Username = null;
					else entity.Username = Convert.ToString(value);
				}
			}
				
			public System.String FirstName
			{
				get
				{
					System.String data = entity.FirstName;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.FirstName = null;
					else entity.FirstName = Convert.ToString(value);
				}
			}
				
			public System.String LastName
			{
				get
				{
					System.String data = entity.LastName;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.LastName = null;
					else entity.LastName = Convert.ToString(value);
				}
			}
				
			public System.String IsSuperUser
			{
				get
				{
					System.Boolean? data = entity.IsSuperUser;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.IsSuperUser = null;
					else entity.IsSuperUser = Convert.ToBoolean(value);
				}
			}
				
			public System.String AffiliateId
			{
				get
				{
					System.Int32? data = entity.AffiliateId;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.AffiliateId = null;
					else entity.AffiliateId = Convert.ToInt32(value);
				}
			}
				
			public System.String Email
			{
				get
				{
					System.String data = entity.Email;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.Email = null;
					else entity.Email = Convert.ToString(value);
				}
			}
				
			public System.String DisplayName
			{
				get
				{
					System.String data = entity.DisplayName;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.DisplayName = null;
					else entity.DisplayName = Convert.ToString(value);
				}
			}
				
			public System.String UpdatePassword
			{
				get
				{
					System.Boolean? data = entity.UpdatePassword;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.UpdatePassword = null;
					else entity.UpdatePassword = Convert.ToBoolean(value);
				}
			}
				
			public System.String LastIPAddress
			{
				get
				{
					System.String data = entity.LastIPAddress;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.LastIPAddress = null;
					else entity.LastIPAddress = Convert.ToString(value);
				}
			}
				
			public System.String IsDeleted
			{
				get
				{
					System.Boolean? data = entity.IsDeleted;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.IsDeleted = null;
					else entity.IsDeleted = Convert.ToBoolean(value);
				}
			}
				
			public System.String CreatedByUserID
			{
				get
				{
					System.Int32? data = entity.CreatedByUserID;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.CreatedByUserID = null;
					else entity.CreatedByUserID = Convert.ToInt32(value);
				}
			}
				
			public System.String CreatedOnDate
			{
				get
				{
					System.DateTime? data = entity.CreatedOnDate;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.CreatedOnDate = null;
					else entity.CreatedOnDate = Convert.ToDateTime(value);
				}
			}
				
			public System.String LastModifiedByUserID
			{
				get
				{
					System.Int32? data = entity.LastModifiedByUserID;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.LastModifiedByUserID = null;
					else entity.LastModifiedByUserID = Convert.ToInt32(value);
				}
			}
				
			public System.String LastModifiedOnDate
			{
				get
				{
					System.DateTime? data = entity.LastModifiedOnDate;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.LastModifiedOnDate = null;
					else entity.LastModifiedOnDate = Convert.ToDateTime(value);
				}
			}
			

			private esUser entity;
		}
		
		[NonSerialized]
		private esStrings esstrings;		
		
		#endregion
		
		#region Housekeeping methods

		override protected IMetadata Meta
		{
			get
			{
				return UserMetadata.Meta();
			}
		}

		#endregion		
		
		#region Query Logic

		public UserQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new UserQuery();
					InitQuery(this.query);
				}

				return this.query;
			}
		}

		public bool Load(UserQuery query)
		{
			this.query = query;
			InitQuery(this.query);
			return this.Query.Load();
		}
		
		protected void InitQuery(UserQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			
			if (!query.es2.HasConnection)
			{
				query.es2.Connection = ((IEntity)this).Connection;
			}			
		}

		#endregion
		
        [IgnoreDataMember]
		private UserQuery query;		
	}



	[Serializable]
	abstract public partial class esUserCollection : esEntityCollection<User>
	{
		#region Housekeeping methods
		override protected IMetadata Meta
		{
			get
			{
				return UserMetadata.Meta();
			}
		}

		protected override string GetCollectionName()
		{
			return "UserCollection";
		}

		#endregion		
		
		#region Query Logic

	#if (!WindowsCE)
		[BrowsableAttribute(false)]
	#endif
		public UserQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new UserQuery();
					InitQuery(this.query);
				}

				return this.query;
			}
		}

		public bool Load(UserQuery query)
		{
			this.query = query;
			InitQuery(this.query);
			return Query.Load();
		}

		override protected esDynamicQuery GetDynamicQuery()
		{
			if (this.query == null)
			{
				this.query = new UserQuery();
				this.InitQuery(query);
			}
			return this.query;
		}

		protected void InitQuery(UserQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			
			if (!query.es2.HasConnection)
			{
				query.es2.Connection = ((IEntityCollection)this).Connection;
			}			
		}

		protected override void HookupQuery(esDynamicQuery query)
		{
			this.InitQuery((UserQuery)query);
		}

		#endregion
		
		private UserQuery query;
	}



	[Serializable]
	abstract public partial class esUserQuery : esDynamicQuery
	{
		override protected IMetadata Meta
		{
			get
			{
				return UserMetadata.Meta();
			}
		}	
		
		#region QueryItemFromName
		
        protected override esQueryItem QueryItemFromName(string name)
        {
            switch (name)
            {
				case "UserID": return this.UserID;
				case "Username": return this.Username;
				case "FirstName": return this.FirstName;
				case "LastName": return this.LastName;
				case "IsSuperUser": return this.IsSuperUser;
				case "AffiliateId": return this.AffiliateId;
				case "Email": return this.Email;
				case "DisplayName": return this.DisplayName;
				case "UpdatePassword": return this.UpdatePassword;
				case "LastIPAddress": return this.LastIPAddress;
				case "IsDeleted": return this.IsDeleted;
				case "CreatedByUserID": return this.CreatedByUserID;
				case "CreatedOnDate": return this.CreatedOnDate;
				case "LastModifiedByUserID": return this.LastModifiedByUserID;
				case "LastModifiedOnDate": return this.LastModifiedOnDate;

                default: return null;
            }
        }		
		
		#endregion
		
		#region esQueryItems

		public esQueryItem UserID
		{
			get { return new esQueryItem(this, UserMetadata.ColumnNames.UserID, esSystemType.Int32); }
		} 
		
		public esQueryItem Username
		{
			get { return new esQueryItem(this, UserMetadata.ColumnNames.Username, esSystemType.String); }
		} 
		
		public esQueryItem FirstName
		{
			get { return new esQueryItem(this, UserMetadata.ColumnNames.FirstName, esSystemType.String); }
		} 
		
		public esQueryItem LastName
		{
			get { return new esQueryItem(this, UserMetadata.ColumnNames.LastName, esSystemType.String); }
		} 
		
		public esQueryItem IsSuperUser
		{
			get { return new esQueryItem(this, UserMetadata.ColumnNames.IsSuperUser, esSystemType.Boolean); }
		} 
		
		public esQueryItem AffiliateId
		{
			get { return new esQueryItem(this, UserMetadata.ColumnNames.AffiliateId, esSystemType.Int32); }
		} 
		
		public esQueryItem Email
		{
			get { return new esQueryItem(this, UserMetadata.ColumnNames.Email, esSystemType.String); }
		} 
		
		public esQueryItem DisplayName
		{
			get { return new esQueryItem(this, UserMetadata.ColumnNames.DisplayName, esSystemType.String); }
		} 
		
		public esQueryItem UpdatePassword
		{
			get { return new esQueryItem(this, UserMetadata.ColumnNames.UpdatePassword, esSystemType.Boolean); }
		} 
		
		public esQueryItem LastIPAddress
		{
			get { return new esQueryItem(this, UserMetadata.ColumnNames.LastIPAddress, esSystemType.String); }
		} 
		
		public esQueryItem IsDeleted
		{
			get { return new esQueryItem(this, UserMetadata.ColumnNames.IsDeleted, esSystemType.Boolean); }
		} 
		
		public esQueryItem CreatedByUserID
		{
			get { return new esQueryItem(this, UserMetadata.ColumnNames.CreatedByUserID, esSystemType.Int32); }
		} 
		
		public esQueryItem CreatedOnDate
		{
			get { return new esQueryItem(this, UserMetadata.ColumnNames.CreatedOnDate, esSystemType.DateTime); }
		} 
		
		public esQueryItem LastModifiedByUserID
		{
			get { return new esQueryItem(this, UserMetadata.ColumnNames.LastModifiedByUserID, esSystemType.Int32); }
		} 
		
		public esQueryItem LastModifiedOnDate
		{
			get { return new esQueryItem(this, UserMetadata.ColumnNames.LastModifiedOnDate, esSystemType.DateTime); }
		} 
		
		#endregion
		
	}


	
	public partial class User : esUser
	{

		#region AgentCollectionByUserId - Zero To Many
		
		static public esPrefetchMap Prefetch_AgentCollectionByUserId
		{
			get
			{
				esPrefetchMap map = new esPrefetchMap();
				map.PrefetchDelegate = DNNspot.LiveChat.DataModel.User.AgentCollectionByUserId_Delegate;
				map.PropertyName = "AgentCollectionByUserId";
				map.MyColumnName = "UserId";
				map.ParentColumnName = "UserID";
				map.IsMultiPartKey = false;
				return map;
			}
		}		
		
		static private void AgentCollectionByUserId_Delegate(esPrefetchParameters data)
		{
			UserQuery parent = new UserQuery(data.NextAlias());

			AgentQuery me = data.You != null ? data.You as AgentQuery : new AgentQuery(data.NextAlias());

			if (data.Root == null)
			{
				data.Root = me;
			}
			
			data.Root.InnerJoin(parent).On(parent.UserID == me.UserId);

			data.You = parent;
		}			
		
		/// <summary>
		/// Zero to Many
		/// Foreign Key Name - FK_DNNspot_LiveChat_Agents_Users
		/// </summary>

		[XmlIgnore]
		public AgentCollection AgentCollectionByUserId
		{
			get
			{
				if(this._AgentCollectionByUserId == null)
				{
					this._AgentCollectionByUserId = new AgentCollection();
					this._AgentCollectionByUserId.es.Connection.Name = this.es.Connection.Name;
					this.SetPostSave("AgentCollectionByUserId", this._AgentCollectionByUserId);
				
					if (this.UserID != null)
					{
						if (!this.es.IsLazyLoadDisabled)
						{
							this._AgentCollectionByUserId.Query.Where(this._AgentCollectionByUserId.Query.UserId == this.UserID);
							this._AgentCollectionByUserId.Query.Load();
						}

						// Auto-hookup Foreign Keys
						this._AgentCollectionByUserId.fks.Add(AgentMetadata.ColumnNames.UserId, this.UserID);
					}
				}

				return this._AgentCollectionByUserId;
			}
			
			set 
			{ 
				if (value != null) throw new Exception("'value' Must be null"); 
			 
				if (this._AgentCollectionByUserId != null) 
				{ 
					this.RemovePostSave("AgentCollectionByUserId"); 
					this._AgentCollectionByUserId = null;
					
				} 
			} 			
		}
			
		
		private AgentCollection _AgentCollectionByUserId;
		#endregion

		#region ClientCollectionByUserId - Zero To Many
		
		static public esPrefetchMap Prefetch_ClientCollectionByUserId
		{
			get
			{
				esPrefetchMap map = new esPrefetchMap();
				map.PrefetchDelegate = DNNspot.LiveChat.DataModel.User.ClientCollectionByUserId_Delegate;
				map.PropertyName = "ClientCollectionByUserId";
				map.MyColumnName = "UserId";
				map.ParentColumnName = "UserID";
				map.IsMultiPartKey = false;
				return map;
			}
		}		
		
		static private void ClientCollectionByUserId_Delegate(esPrefetchParameters data)
		{
			UserQuery parent = new UserQuery(data.NextAlias());

			ClientQuery me = data.You != null ? data.You as ClientQuery : new ClientQuery(data.NextAlias());

			if (data.Root == null)
			{
				data.Root = me;
			}
			
			data.Root.InnerJoin(parent).On(parent.UserID == me.UserId);

			data.You = parent;
		}			
		
		/// <summary>
		/// Zero to Many
		/// Foreign Key Name - FK_DNNspot_LiveChat_Clients_Users
		/// </summary>

		[XmlIgnore]
		public ClientCollection ClientCollectionByUserId
		{
			get
			{
				if(this._ClientCollectionByUserId == null)
				{
					this._ClientCollectionByUserId = new ClientCollection();
					this._ClientCollectionByUserId.es.Connection.Name = this.es.Connection.Name;
					this.SetPostSave("ClientCollectionByUserId", this._ClientCollectionByUserId);
				
					if (this.UserID != null)
					{
						if (!this.es.IsLazyLoadDisabled)
						{
							this._ClientCollectionByUserId.Query.Where(this._ClientCollectionByUserId.Query.UserId == this.UserID);
							this._ClientCollectionByUserId.Query.Load();
						}

						// Auto-hookup Foreign Keys
						this._ClientCollectionByUserId.fks.Add(ClientMetadata.ColumnNames.UserId, this.UserID);
					}
				}

				return this._ClientCollectionByUserId;
			}
			
			set 
			{ 
				if (value != null) throw new Exception("'value' Must be null"); 
			 
				if (this._ClientCollectionByUserId != null) 
				{ 
					this.RemovePostSave("ClientCollectionByUserId"); 
					this._ClientCollectionByUserId = null;
					
				} 
			} 			
		}
			
		
		private ClientCollection _ClientCollectionByUserId;
		#endregion

		#region UserPortalCollectionByUserId - Zero To Many
		
		static public esPrefetchMap Prefetch_UserPortalCollectionByUserId
		{
			get
			{
				esPrefetchMap map = new esPrefetchMap();
				map.PrefetchDelegate = DNNspot.LiveChat.DataModel.User.UserPortalCollectionByUserId_Delegate;
				map.PropertyName = "UserPortalCollectionByUserId";
				map.MyColumnName = "UserId";
				map.ParentColumnName = "UserID";
				map.IsMultiPartKey = false;
				return map;
			}
		}		
		
		static private void UserPortalCollectionByUserId_Delegate(esPrefetchParameters data)
		{
			UserQuery parent = new UserQuery(data.NextAlias());

			UserPortalQuery me = data.You != null ? data.You as UserPortalQuery : new UserPortalQuery(data.NextAlias());

			if (data.Root == null)
			{
				data.Root = me;
			}
			
			data.Root.InnerJoin(parent).On(parent.UserID == me.UserId);

			data.You = parent;
		}			
		
		/// <summary>
		/// Zero to Many
		/// Foreign Key Name - FK_UserPortals_Users
		/// </summary>

		[XmlIgnore]
		public UserPortalCollection UserPortalCollectionByUserId
		{
			get
			{
				if(this._UserPortalCollectionByUserId == null)
				{
					this._UserPortalCollectionByUserId = new UserPortalCollection();
					this._UserPortalCollectionByUserId.es.Connection.Name = this.es.Connection.Name;
					this.SetPostSave("UserPortalCollectionByUserId", this._UserPortalCollectionByUserId);
				
					if (this.UserID != null)
					{
						if (!this.es.IsLazyLoadDisabled)
						{
							this._UserPortalCollectionByUserId.Query.Where(this._UserPortalCollectionByUserId.Query.UserId == this.UserID);
							this._UserPortalCollectionByUserId.Query.Load();
						}

						// Auto-hookup Foreign Keys
						this._UserPortalCollectionByUserId.fks.Add(UserPortalMetadata.ColumnNames.UserId, this.UserID);
					}
				}

				return this._UserPortalCollectionByUserId;
			}
			
			set 
			{ 
				if (value != null) throw new Exception("'value' Must be null"); 
			 
				if (this._UserPortalCollectionByUserId != null) 
				{ 
					this.RemovePostSave("UserPortalCollectionByUserId"); 
					this._UserPortalCollectionByUserId = null;
					
				} 
			} 			
		}
			
		
		private UserPortalCollection _UserPortalCollectionByUserId;
		#endregion

		
		protected override esEntityCollectionBase CreateCollectionForPrefetch(string name)
		{
			esEntityCollectionBase coll = null;

			switch (name)
			{
				case "AgentCollectionByUserId":
					coll = this.AgentCollectionByUserId;
					break;
				case "ClientCollectionByUserId":
					coll = this.ClientCollectionByUserId;
					break;
				case "UserPortalCollectionByUserId":
					coll = this.UserPortalCollectionByUserId;
					break;	
			}

			return coll;
		}		
		/// <summary>
		/// Used internally by the entity's hierarchical properties.
		/// </summary>
		protected override List<esPropertyDescriptor> GetHierarchicalProperties()
		{
			List<esPropertyDescriptor> props = new List<esPropertyDescriptor>();
			
			props.Add(new esPropertyDescriptor(this, "AgentCollectionByUserId", typeof(AgentCollection), new Agent()));
			props.Add(new esPropertyDescriptor(this, "ClientCollectionByUserId", typeof(ClientCollection), new Client()));
			props.Add(new esPropertyDescriptor(this, "UserPortalCollectionByUserId", typeof(UserPortalCollection), new UserPortal()));
		
			return props;
		}
		
		/// <summary>
		/// Called by ApplyPostSaveKeys 
		/// </summary>
		/// <param name="coll">The collection to enumerate over</param>
		/// <param name="key">"The column name</param>
		/// <param name="value">The column value</param>
		private void Apply(esEntityCollectionBase coll, string key, object value)
		{
			foreach (esEntity obj in coll)
			{
				if (obj.es.IsAdded)
				{
					obj.SetProperty(key, value);
				}
			}
		}
		
		/// <summary>
		/// Used internally for retrieving AutoIncrementing keys
		/// during hierarchical PostSave.
		/// </summary>
		protected override void ApplyPostSaveKeys()
		{
			if(this._AgentCollectionByUserId != null)
			{
				Apply(this._AgentCollectionByUserId, "UserId", this.UserID);
			}
			if(this._ClientCollectionByUserId != null)
			{
				Apply(this._ClientCollectionByUserId, "UserId", this.UserID);
			}
			if(this._UserPortalCollectionByUserId != null)
			{
				Apply(this._UserPortalCollectionByUserId, "UserId", this.UserID);
			}
		}
		
	}
	



	[Serializable]
	public partial class UserMetadata : esMetadata, IMetadata
	{
		#region Protected Constructor
		protected UserMetadata()
		{
			m_columns = new esColumnMetadataCollection();
			esColumnMetadata c;

			c = new esColumnMetadata(UserMetadata.ColumnNames.UserID, 0, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = UserMetadata.PropertyNames.UserID;
			c.IsInPrimaryKey = true;
			c.IsAutoIncrement = true;
			c.NumericPrecision = 10;
			m_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.Username, 1, typeof(System.String), esSystemType.String);
			c.PropertyName = UserMetadata.PropertyNames.Username;
			c.CharacterMaxLength = 100;
			m_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.FirstName, 2, typeof(System.String), esSystemType.String);
			c.PropertyName = UserMetadata.PropertyNames.FirstName;
			c.CharacterMaxLength = 50;
			m_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.LastName, 3, typeof(System.String), esSystemType.String);
			c.PropertyName = UserMetadata.PropertyNames.LastName;
			c.CharacterMaxLength = 50;
			m_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.IsSuperUser, 4, typeof(System.Boolean), esSystemType.Boolean);
			c.PropertyName = UserMetadata.PropertyNames.IsSuperUser;
			c.HasDefault = true;
			c.Default = @"((0))";
			m_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.AffiliateId, 5, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = UserMetadata.PropertyNames.AffiliateId;
			c.NumericPrecision = 10;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.Email, 6, typeof(System.String), esSystemType.String);
			c.PropertyName = UserMetadata.PropertyNames.Email;
			c.CharacterMaxLength = 256;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.DisplayName, 7, typeof(System.String), esSystemType.String);
			c.PropertyName = UserMetadata.PropertyNames.DisplayName;
			c.CharacterMaxLength = 128;
			c.HasDefault = true;
			c.Default = @"('')";
			m_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.UpdatePassword, 8, typeof(System.Boolean), esSystemType.Boolean);
			c.PropertyName = UserMetadata.PropertyNames.UpdatePassword;
			c.HasDefault = true;
			c.Default = @"((0))";
			m_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.LastIPAddress, 9, typeof(System.String), esSystemType.String);
			c.PropertyName = UserMetadata.PropertyNames.LastIPAddress;
			c.CharacterMaxLength = 50;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.IsDeleted, 10, typeof(System.Boolean), esSystemType.Boolean);
			c.PropertyName = UserMetadata.PropertyNames.IsDeleted;
			c.HasDefault = true;
			c.Default = @"((0))";
			m_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.CreatedByUserID, 11, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = UserMetadata.PropertyNames.CreatedByUserID;
			c.NumericPrecision = 10;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.CreatedOnDate, 12, typeof(System.DateTime), esSystemType.DateTime);
			c.PropertyName = UserMetadata.PropertyNames.CreatedOnDate;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.LastModifiedByUserID, 13, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = UserMetadata.PropertyNames.LastModifiedByUserID;
			c.NumericPrecision = 10;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(UserMetadata.ColumnNames.LastModifiedOnDate, 14, typeof(System.DateTime), esSystemType.DateTime);
			c.PropertyName = UserMetadata.PropertyNames.LastModifiedOnDate;
			c.IsNullable = true;
			m_columns.Add(c);
				
		}
		#endregion	
	
		static public UserMetadata Meta()
		{
			return meta;
		}	
		
		public Guid DataID
		{
			get { return base.m_dataID; }
		}	
		
		public bool MultiProviderMode
		{
			get { return false; }
		}		

		public esColumnMetadataCollection Columns
		{
			get	{ return base.m_columns; }
		}
		
		#region ColumnNames
		public class ColumnNames
		{ 
			 public const string UserID = "UserID";
			 public const string Username = "Username";
			 public const string FirstName = "FirstName";
			 public const string LastName = "LastName";
			 public const string IsSuperUser = "IsSuperUser";
			 public const string AffiliateId = "AffiliateId";
			 public const string Email = "Email";
			 public const string DisplayName = "DisplayName";
			 public const string UpdatePassword = "UpdatePassword";
			 public const string LastIPAddress = "LastIPAddress";
			 public const string IsDeleted = "IsDeleted";
			 public const string CreatedByUserID = "CreatedByUserID";
			 public const string CreatedOnDate = "CreatedOnDate";
			 public const string LastModifiedByUserID = "LastModifiedByUserID";
			 public const string LastModifiedOnDate = "LastModifiedOnDate";
		}
		#endregion	
		
		#region PropertyNames
		public class PropertyNames
		{ 
			 public const string UserID = "UserID";
			 public const string Username = "Username";
			 public const string FirstName = "FirstName";
			 public const string LastName = "LastName";
			 public const string IsSuperUser = "IsSuperUser";
			 public const string AffiliateId = "AffiliateId";
			 public const string Email = "Email";
			 public const string DisplayName = "DisplayName";
			 public const string UpdatePassword = "UpdatePassword";
			 public const string LastIPAddress = "LastIPAddress";
			 public const string IsDeleted = "IsDeleted";
			 public const string CreatedByUserID = "CreatedByUserID";
			 public const string CreatedOnDate = "CreatedOnDate";
			 public const string LastModifiedByUserID = "LastModifiedByUserID";
			 public const string LastModifiedOnDate = "LastModifiedOnDate";
		}
		#endregion	

		public esProviderSpecificMetadata GetProviderMetadata(string mapName)
		{
			MapToMeta mapMethod = mapDelegates[mapName];

			if (mapMethod != null)
				return mapMethod(mapName);
			else
				return null;
		}
		
		#region MAP esDefault
		
		static private int RegisterDelegateesDefault()
		{
			// This is only executed once per the life of the application
			lock (typeof(UserMetadata))
			{
				if(UserMetadata.mapDelegates == null)
				{
					UserMetadata.mapDelegates = new Dictionary<string,MapToMeta>();
				}
				
				if (UserMetadata.meta == null)
				{
					UserMetadata.meta = new UserMetadata();
				}
				
				MapToMeta mapMethod = new MapToMeta(meta.esDefault);
				mapDelegates.Add("esDefault", mapMethod);
				mapMethod("esDefault");
			}
			return 0;
		}			

		private esProviderSpecificMetadata esDefault(string mapName)
		{
			if(!m_providerMetadataMaps.ContainsKey(mapName))
			{
				esProviderSpecificMetadata meta = new esProviderSpecificMetadata();			


				meta.AddTypeMap("UserID", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("Username", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("FirstName", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("LastName", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("IsSuperUser", new esTypeMap("bit", "System.Boolean"));
				meta.AddTypeMap("AffiliateId", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("Email", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("DisplayName", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("UpdatePassword", new esTypeMap("bit", "System.Boolean"));
				meta.AddTypeMap("LastIPAddress", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("IsDeleted", new esTypeMap("bit", "System.Boolean"));
				meta.AddTypeMap("CreatedByUserID", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("CreatedOnDate", new esTypeMap("datetime", "System.DateTime"));
				meta.AddTypeMap("LastModifiedByUserID", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("LastModifiedOnDate", new esTypeMap("datetime", "System.DateTime"));			
				
				
				
				meta.Source = "Users";
				meta.Destination = "Users";
				
				meta.spInsert = "proc_UsersInsert";				
				meta.spUpdate = "proc_UsersUpdate";		
				meta.spDelete = "proc_UsersDelete";
				meta.spLoadAll = "proc_UsersLoadAll";
				meta.spLoadByPrimaryKey = "proc_UsersLoadByPrimaryKey";
				
				this.m_providerMetadataMaps["esDefault"] = meta;
			}
			
			return this.m_providerMetadataMaps["esDefault"];
		}

		#endregion

		static private UserMetadata meta;
		static protected Dictionary<string, MapToMeta> mapDelegates;
		static private int _esDefault = RegisterDelegateesDefault();
	}
}
